package com.sky.wsp.spring.jackson.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.ContextAttributes;
import com.sky.wsp.spring.jackson.config.properties.JacksonProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 */
@Configuration
@EnableConfigurationProperties(JacksonProperties.class)
public class JacksonConfig {
    @Bean
    public ObjectMapper objectMapper(JacksonProperties props) {
        ObjectMapper mapper = new ObjectMapper();
        ContextAttributes attrs = ContextAttributes.getEmpty()
                .withSharedAttribute("mobile", props.getMobile())
                .withSharedAttribute("email", props.getEmail())
                .withSharedAttribute("identity", props.getIdentity());
        mapper.setDefaultAttributes(attrs);
        return mapper;
    }
}